package com.qf.java2201.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @date 2022/5/28
 * @desc
 */
@Data
public class R {

    private Boolean success;   // 是否成功

    private Integer code;   // 响应的状态码


    private String message;   // 返回的消息


    private Map<Object,Object> data = new HashMap<>();  // 返回的数据


    public static R ok(){
        R r = new R();
        r.setCode(20000);
        r.setMessage("success");
        r.setSuccess(true);


        return r;
    }


    public static R error(){
        R r = new R();

        return r;
    }


    public R success(Boolean success){
        this.setSuccess(success);
        return this;
    }


    public R message(String message){
        this.setMessage(message);
        return this;
    }



    public R code(Integer code){
        this.setCode(code);
        return this;
    }




    public R data(Object key,Object value){
        this.data.put(key,value);
        return this;
    }


    public R data(Map<Object, Object> map){
        this.setData(map);
        return this;
    }

}
